import baseURL from '../axios/url'
// 添加请求头【只有登录页用到】
export const addHeaders = (token,callRes,callErr) => {
	let params = {
		"author": "maxiaoqu.com",
		"Authorization": token
	}
	nativeApi.nativeMethod("http","addHeaders",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 移除请求头【只有登录页\退出页用到】
export const removeHeaders =  (callRes,callErr) => {
    nativeApi.nativeMethodNoParams("http","removeHeaders",res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 拍照
export const openCamera = (callRes,callErr) => {
    nativeApi.nativeMethodNoParams("camera","openCamera",res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 启动定位[time=>类型：Number 单位：秒]【只有登录页用到】
export const startLocationService = (time,callRes,callErr) => {
	let params = {
		span: time,
		uri: baseURL.dip+'/zuul/userCenter/location/addLocation'
	}
    nativeApi.nativeMethod("lbs","startLocationService",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 关闭定位[time=>类型：Number 单位：秒]【只有登录页用到】
export const stopLocationService = (callRes,callErr) => {
    nativeApi.nativeMethodNoParams("lbs","stopLocationService",res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 获取当前位置
export const getLocation = (callRes,callErr) => {
    nativeApi.nativeMethodNoParams("lbs","getLocation",res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 改变定位频率[time=>类型：Number 单位：秒]
export const changeLocateSpan = (time,callRes,callErr) => {
	let params = {
		span: time
	}
    nativeApi.nativeMethod("lbs","changeLocateSpan",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 存放到缓存里
//data = {
//	key: key // 当前要存的key值
//	data: data // 当前要存的data值（Array、String、Object）
//}
export const saveLocalStorage = (data,callRes,callErr) => {
	let params = {}
		params = data
    nativeApi.nativeMethod("storage","saveLocalStorage",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 取缓存里的东西
//data = {
//	key: key // 当前要取的key值
//}
export const getLocalStorage = (data,callRes,callErr) => {
	let params = {}
		params = data
    nativeApi.nativeMethod("storage","getLocalStorage",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 清除缓存里的东西
//data = {
//	key: key // 当前要清除的key值
//}
export const deleteLocalStorage = (data,callRes,callErr) => {
	let params = {}
		params = data
    nativeApi.nativeMethod("storage","deleteLocalStorage",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 开启导航[locat=>类型：Object]
//locat = {
//	myLat: 40.052834, // 当前的经纬度
//  myLon: 116.313882, // 当前的经纬度
//  toLat: 39.915526, // 目的地的经纬度
//  toLon: 116.403847 // 目的地的经纬度
//}
export const startNavi = (locat,callRes,callErr) => {
	let params = locat
    nativeApi.nativeMethod("lbs","startNavi",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

/* 开启特殊巡视/线路检修 地图页[km[半径]=>类型：Number 单位：Km]，
*  tsk[模块类型]：特殊巡视传0，线路检修传1
*/
export const stSelectTower = (km,tsk,callRes,callErr) => {
	console.log('km',km);
	console.log('tsk',tsk);
	let params = {
		range: km,
		taskType:tsk
	}
	console.log('params',params);
    nativeApi.nativeMethod("lbs","stSelectTower",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 启动消息服务
export const startMpush = (userId,callRes,callErr) => {
	let params = {
        userId:userId,
        allocServer: baseURL.pip
    }
	nativeApi.nativeMethod("mpush","startMpush",params,res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}

// 停止消息服务
export const stopMpush = (callRes,callErr) => {
	nativeApi.nativeMethodNoParams("mpush","stopMpush",res => {
    	callRes(res)
	},err => {
    	callErr(err)
    })
}